package cn.tedu.user.management.dao.persist.repository.impl;

import cn.tedu.user.management.dao.persist.mapper.SectionJobMapper;
import cn.tedu.user.management.dao.persist.repository.ISectionJobRepository;
import cn.tedu.user.management.pojo.entity.SectionJob;
import cn.tedu.user.management.pojo.vo.JobEnableListItemVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 处理用户数据的数据访问实现类
 *
 * @author java@tedu.cn
 * @version 0.0.1
 */
@Slf4j
@Repository
public class SectionJobRepositoryImpl implements ISectionJobRepository {

    @Autowired
    private SectionJobMapper sectionJobMapper;

    public SectionJobRepositoryImpl() {
        log.debug("创建数据访问实现类对象：UserRepositoryImpl");
    }

    @Override
    public int updateById(SectionJob sectionJob) {
        log.debug("开始执行【更新用户】的数据访问，参数：{}", sectionJob);
        return sectionJobMapper.updateById(sectionJob);
    }

    @Override
    public int countBySectionIdAndJobId(Long sectionId, Long jobId) {
        log.debug("开始执行【根据sectionId和jobId查询section_job表中数据】的数据访问，参数：{},{}", sectionId, jobId);
        QueryWrapper<SectionJob> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("section_id", sectionId)
                .eq("job_id", jobId);
        return sectionJobMapper.selectCount(queryWrapper);
    }

    @Override
    public int insert(SectionJob sectionJob) {
        log.debug("开始执行【向section_job表中插入数据】的数据访问，参数：{}", sectionJob);
        return sectionJobMapper.insert(sectionJob);
    }

    @Override
    public List<JobEnableListItemVO> enableList(Long sectionId) {
        log.debug("开始执行【查询招聘职位列表】，部门：{}", sectionId);
        return sectionJobMapper.enableList(sectionId);
    }

    @Override
    public int countBySectionId(Long sectionId) {
        log.debug("开始执行【查据部门id查看职位数量】，部门：{}", sectionId);
        QueryWrapper<SectionJob> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("section_id", sectionId);
        return sectionJobMapper.selectCount(queryWrapper);
    }

    @Override
    public int countById(Long id) {
        log.debug("开始执行【根据id查看指定部门的职位数量】，部门：{}", id);
        QueryWrapper<SectionJob> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", id);
        return sectionJobMapper.selectCount(queryWrapper);
    }

    @Override
    public int deleteById(Long id) {
        log.debug("开始执行【根据id删除部门职位关联表数据】，部门：{}", id);
        return sectionJobMapper.deleteById(id);
    }

    @Override
    public Long selectJobIdById(Long id) {
        log.debug("开始执行【根据id查job_id】，id：{}", id);
        return sectionJobMapper.selectJobIdById(id);
    }

    @Override
    public Long selectSectionJobId(Long sectionId, Long jobId) {
        log.debug("开始执行【根据SectionId和JobId和jobId获取sectionJobId】，sectionId：{}，jobId：{}", sectionId, jobId);
        return sectionJobMapper.selectId(sectionId, jobId);
    }

    @Override
    public int update(SectionJob SectionJob) {
        log.debug("开始执行【根据SectionJobId更新数据】, {}", SectionJob);
        return sectionJobMapper.updateById(SectionJob);
    }

}
